define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/order/index',
                    del_url: 'user/order/del',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {'wxpay': __('Wxpay'), 'alipay':__('Alipay')}, formatter: function(value){
                        	let html = '';
                        	switch (value){
                        		case 'wxpay': html = '<span class=text-success>'+__('Wxpay')+'</span>'; break;  
                        		case 'alipay': html = '<span class=text-info>'+__('Alipay')+'</span>'; break;  
                        		default : html = '<span class=text-warning>不存在</span>'; break;  
                        	}
                        	return html;
                        }},
                        {field: 'event', title: __('Event'), searchList: {'support':__('Support'), 'member':__('Member')}, formatter: function(value){
                        	let html = '';
                        	switch (value){
                        		case 'support': html = '<span class=text-danger>'+__('Support')+'</span>'; break;  
                        		case 'member': html = '<span class=text-primary>'+__('Member')+'</span>'; break;  
                        		default : html = '<span class=text-warning>不存在</span>'; break;  
                        	}
                        	return html;
                        }},
                        {field: 'trade_no', title: __('Trade'), operate: 'LIKE'},
                        {field: 'money', title: __('Money'), operate: 'BETWEEN', sortable:true},
                        {field: 'status', title: __('Status'), searchList: {2: __('Fail'),1: __('Success'), 0: __('Create')}, sortable: false, formatter: function(value){
                        	let html = '';
                        	switch (value){
                        		case 0: html = '<span class=text-danger>'+__('Create')+'</span>'; break;
                        		case 1: html = '<span class=text-success>'+__('Success')+'</span>'; break;
                        		case 2: html = '<span class=text-warning>'+__('Fail')+'</span>'; break; 
                        	}
                        	return html;
                        }},
                        {field: 'create_time', title: __('CreateTime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});